package al4th.chp1;

import al4th.StdLib.StdOut;

/**
 * @Author : wanghongfu
 * @Date : Created in 下午9:43  17/10/17
 * @Email 1583505981@qq.comk
 * @Description:
 */
public class Ex_1_1_18 {
    public static int mystery(int a, int b){
        StdOut.printf("%3d,%3d\n",a,b);
        if (b==0) return 0;
        if (b%2==0) return mystery(a+a,b/2);
        return mystery(a+a,b/2)+a;
    }

    public static int mystery1(int a,int b){
        StdOut.printf("%7d,%3d\n",a,b);
        if (b==0) return 1;
        if (b%2==0) return mystery1(a*a,b/2);
        return mystery1(a*a,b/2)*a;
    }

    public static void main(String[] args) {
        StdOut.println("Result: "+mystery(5,7));
        StdOut.println();
        StdOut.println("Result: "+mystery1(5,7));
    }
}
